$(function () {

    $("#xsht_gspzList_detail").datagrid({
        url: $.webPath() + '/base/gspz/gspzListByHtId?xshtId=' + $("#xsht_id").val(),
        fit: true,
        fitColumns: true,
        singleSelect: true,
        checkbox: true,
        checkOnSelect: true,
        selectOnCheck: true,
        showFooter: false,
        rownumbers: false,
        columns: [
            [
                {field: 'id', title: 'ID', hidden: true, width: 100, align: 'center'},
                {field: 'mc', title: '公式名称', width: 100, formatter: gspzCell, align: 'center'},
                {field: 'szr.xm', title: '设置人', width: 100, align: 'center'},
                {field: 'jzrq', title: '截止日期', width: 100, align: 'center'},
                {field: 'sfqy', title: '启用', width: 100, align: 'center',
                    formatter: function (value) {
                        if (value == 1)
                            return '是';
                        else
                            return '否';
                    }
                }
            ]
        ]
    })

    $("span.ljtip").ljDetail($("#xsht_detail_ljtip").val(), {
        position: 'top'
    });

    $("#xsht_tabs .previewImg").lightbox({
        fitToScreen: true,
        loopImages: true,
        imageClickClose: false,
        disableNavbarLinks: true
    });
    $('#xsht_tabs').tabs({

        border: false,
        onSelect: function (title) {
            if (title == "合同文本") {
                // 加载合同文本
                $.ajax({
                    type: "POST",
                    url: $.webPath() + "/htdygl/htwb/htwbDetail",
                    dataType: "html",
                    data: {htdyId: $("[name='htdy.xsht.id']").val(), htId: $("[name='xsht.name.id']").val()},
                    beforeSend: function () {
//                        $.messager.progress();
                    },
                    success: function (data) {
//                        $.messager.progress("close");
                        $('#htwb_xsht_detail_id').html(data);
                        var inputs = document.getElementById("page").getElementsByTagName("input");
                        for (var i = 0; i < inputs.length; i++) {
                            if (null != inputs[i].name) {
                                inputs[i].setAttribute("disabled", "disabled");
                            }
                        }

                        if (data.statusCode == 300) {
                        }
                        if (data.statusCode == 200) {
                        }
                    }
                });
            }
        }
    });

    $("#xshtmx_detail_toolbar a[name='exp']").click(function () {
        var mxUrl = $("#xsht_xshtmx_table").attr("url");
        var s = mxUrl.split("?");
        s[0] += "_exp";
        var expUrl = s.join("?");
        window.open(expUrl);
    });

    $("#xsht_xshtmx_table").datagrid({
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#xsht_xsd_table").datagrid({
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#xsht_fkjl_table").datagrid({
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

});

function viewZddhXsDetail(id) {
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/htgl/cghtgl/cghtgl_detail?cghtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

function viewXshtXyDetail(xyId, xyType) {
    if (xyType != null && xyType == "Cgxy") {
        var type = 1;
    } else if (xyType != null && xyType == "Xsxy") {
        type = 2;
    } else if (xyType != null && xyType == "Sfxy") {
        type = 3;
    }
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/jhgl/xygl/htwb_xsht_detail_id?type=" + type + "&xyId=" + xyId,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}
